/***************************************************************************\
 * The Mattise Kernel														*
 * Copyright 2007 Matthew Iselin											*
 * Licensed under the GPL													*
 *																			*
 * paging.h																	*
 *																			*
 * (not used) Sets up paging.												*
 *																			*
\***************************************************************************/

// Control registers: read/write

// READ
unsigned int read_cr0();
unsigned int read_cr2();
unsigned int read_cr3();

// WRITE
void write_cr0( unsigned int cr0 );
void write_cr3( unsigned int cr3 );

// page flags
#define PF_PRESENT		0x1
#define PF_READWRITE	0x2
#define PF_SUPERVISOR	0x0
#define PF_USER			0x4
#define PF_GLOBAL		0x100

/// Gets the kernel page directory
uint_t GetKernelPageDir();

/// Gets the virtual address of the current page directory
uint_t GetCurrentPageDirVirtual();

/// Creates a new address space with a certain size, returning the page directory location
uint_t CreateAddressSpace( uint_t pagecount );

/// Gets the physical address for a virtual address
uint_t GetPhysicalAddress( uint_t pdir, uint_t virt_addr );

/// Gets the entry for a virtual address
uint_t GetAddressEntry( uint_t pdir, uint_t virt_addr );

/// Gets the page table entry for a virtual address
uint_t GetPTEntry( uint_t pdir, uint_t virt_addr );

/// Maps a physical address into the current page directory
void MapUserPhysicalAddress( uint_t virt_addr, uint_t phys_addr, uint_t flags );

/// Sets a physical address mapping
void MapPhysicalAddress( uint_t pdir, uint_t virt_addr, uint_t phys_addr, uint_t flags );

/// Checks if a virtual address is mapped
bool IsMapped( uint_t pdir, uint_t virt_addr );

/// Allocates space for a page table
void AllocatePageTable( uint_t pdir, uint_t virt_addr, uint_t flags, uint_t map_to_himem = 0 );
